const Router = require('koa-router')
const { resDesign } = require('@/utils/dataDesign')
const SystemService = require('@/service/system.service')
const HTTP_CODE = require('@/app/http-code')

const userRouter = new Router({ prefix: '/system/user' })

// 查询用户列表
userRouter.get('/list', async (ctx) => {
  try {
    const data = await SystemService.selectUsers(ctx.query)
    ctx.body = resDesign({ data })
  } catch (error) {
    console.log(error)
  }
})
userRouter.post('/insert', async (ctx) => {
  try {
    await SystemService.insertUser(ctx.request.body)
    ctx.body = resDesign()
  } catch (error) {
    console.log(error)
  }
})
userRouter.post('/update', async (ctx) => {
  try {
    await SystemService.updateUser(ctx.request.body)
    ctx.body = resDesign()
  } catch (error) {
    console.log(error)
  }
})
userRouter.delete('/delete/:id', async (ctx) => {
  try {
    await SystemService.deleteUser(ctx.params.id)
    ctx.body = resDesign()
  } catch (error) {
    console.log(error)
  }
})

module.exports = userRouter
